package org.huyue.huyuexia.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Update;
import org.huyue.huyuexia.pojo.Query.UserQueryParam;
import org.huyue.huyuexia.pojo.User;
import org.huyue.huyuexia.service.UserService;
import org.huyue.huyuexia.util.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/users")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping
    public Result findAll(UserQueryParam queryParam) {
        return Result.success(userService.findAll(queryParam));
    }
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id) {
        return Result.success(userService.findById(id));
    }
    @PostMapping
    public Result add(@RequestBody User user) {
        userService.add(user);
        return Result.success();
    }
    @DeleteMapping
    public Result delete(@RequestParam Integer id) {
        userService.Delete(id);
        return Result.success();
    }
    @PutMapping
    public Result update(@RequestBody User user) {
        userService.update(user);
        return Result.success();
    }
    // 关注
    @PostMapping("/follow")
    public Result follow(@RequestParam Integer followId) {
        userService.follow(followId);

        return Result.success();


    }
    // 获取每个用户发布的文章数量
    @GetMapping("/articleCount")
    public Result getArticleCount() {
        return Result.success(userService.getArticleCount());
    }


}
